package com.petshop.pets.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.petshop.common.annotation.Log;
import com.petshop.common.core.controller.BaseController;
import com.petshop.common.core.domain.AjaxResult;
import com.petshop.common.enums.BusinessType;
import com.petshop.pets.domain.PetPets;
import com.petshop.pets.service.IPetPetsService;
import com.petshop.common.utils.poi.ExcelUtil;
import com.petshop.common.core.page.TableDataInfo;

/**
 * 宠物信息Controller
 * 
 * @author ruoyi
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/pets/pets")
public class PetPetsController extends BaseController
{
    @Autowired
    private IPetPetsService petPetsService;

    /**
     * 查询宠物信息列表
     */
    @PreAuthorize("@ss.hasPermi('pets:pets:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetPets petPets)
    {
        startPage();
        List<PetPets> list = petPetsService.selectPetPetsList(petPets);
        return getDataTable(list);
    }

    /**
     * 导出宠物信息列表
     */
    @PreAuthorize("@ss.hasPermi('pets:pets:export')")
    @Log(title = "宠物信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetPets petPets)
    {
        List<PetPets> list = petPetsService.selectPetPetsList(petPets);
        ExcelUtil<PetPets> util = new ExcelUtil<PetPets>(PetPets.class);
        util.exportExcel(response, list, "宠物信息数据");
    }

    /**
     * 获取宠物信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('pets:pets:query')")
    @GetMapping(value = "/{petID}")
    public AjaxResult getInfo(@PathVariable("petID") Long petID)
    {
        return success(petPetsService.selectPetPetsByPetID(petID));
    }

    /**
     * 新增宠物信息
     */
    @PreAuthorize("@ss.hasPermi('pets:pets:add')")
    @Log(title = "宠物信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetPets petPets)
    {
        return toAjax(petPetsService.insertPetPets(petPets));
    }

    /**
     * 修改宠物信息
     */
    @PreAuthorize("@ss.hasPermi('pets:pets:edit')")
    @Log(title = "宠物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetPets petPets)
    {
        return toAjax(petPetsService.updatePetPets(petPets));
    }

    /**
     * 删除宠物信息
     */
    @PreAuthorize("@ss.hasPermi('pets:pets:remove')")
    @Log(title = "宠物信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{petIDs}")
    public AjaxResult remove(@PathVariable Long[] petIDs)
    {
        return toAjax(petPetsService.deletePetPetsByPetIDs(petIDs));
    }
}
